using System;
using System.Data;
using System.Configuration;
using MySql.Data.MySqlClient;  

namespace TestProject
{
	public class DB
	{
        private string ConnectionString;
		
        public DB()  
        {
            // get the connection string  
            this.ConnectionString = ConfigurationManager.ConnectionStrings["MySQL"].ConnectionString;
        }
		
        public System.Data.DataSet Select(string query)  
        {  
            MySqlConnection dbcon;  
            using (dbcon = new MySqlConnection(this.ConnectionString))  
            {  
                // open the connection  
                dbcon.Open();
                // create a new adapter between the connection and query  
                MySqlDataAdapter adapter = new MySqlDataAdapter(query, dbcon);
                // create a new dataset to store the query results  
                DataSet ds = new DataSet();  
                // fill the dataset with the results from the adapter,  
                adapter.Fill(ds, "result");  
                // return the dataset  
                return ds;  
            }  
        }
		
        public bool Execute(string query)  
        {  
            MySqlConnection dbcon;  
            using (dbcon = new MySqlConnection(this.ConnectionString))  
            {  
                // create a new SQL command on thie connection  
                MySqlCommand command = new MySqlCommand(query, dbcon);  
                // open the connection  
                dbcon.Open();  
                // execute the query and return the number of affected rows  
                int affectedrows = command.ExecuteNonQuery();  
                // there were no rows affected - the command failed  
                if (affectedrows == 0)  
                {  
                    return false;  
                // the command affected at least one row  
                } else {  
                    return true;  
                }  
            }  
        }  
    }  
}

